package com.open.demo.compose

import android.content.res.Resources
import android.os.Bundle
import android.provider.Settings
import android.util.Log
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.open.demo.R

class LuancherActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            Greeting()
        }

        val isInDeveloperMode = Settings.Global.getInt(applicationContext.contentResolver,
            Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0

        val locales = Resources.getSystem().assets.locales
        val localeList = locales.toList()
        localeList.forEach { 
            Log.d("hailong.qiu", "key:$it")
        }
    }

    @Preview
    @Composable
    fun Greeting() {
        LazyRow(
            modifier = Modifier
                .fillMaxWidth()
                .fillMaxHeight(),
            contentPadding = PaddingValues(60.dp),
            horizontalArrangement = Arrangement.spacedBy(10.dp)
        ) {
            itemsIndexed(listOf(
                Item("榜单", R.drawable.mainview_cloudlist),
                Item("活动", R.drawable.mainview_huodong),
                Item("游戏", R.drawable.mine_handler),
                Item("影视", R.drawable.mine_account)
            )) { index,item ->
                if (index == 3) {
                    Column(verticalArrangement = Arrangement.spacedBy(10.dp)) {
                        var isFocused by remember { mutableStateOf(false) }
                        ItemWidget.ItemView(
                            item = item,
                            isFocused = isFocused,
                            modifier = Modifier
                                .onFocusChanged {
                                    isFocused = it.isFocused
                                }
                                .size(200.dp, 105.dp)
                        )
                        var isFocused2 by remember { mutableStateOf(false) }
                        ItemWidget.ItemView(
                            item = Item("音乐", R.drawable.mainview_tuijian),
                            isFocused = isFocused2,
                            modifier = Modifier
                                .onFocusChanged {
                                    isFocused2 = it.isFocused
                                }
                                .size(200.dp, 105.dp)
                        )
                    }
                } else {
                    var isFocused by remember { mutableStateOf(false) }
                    ItemWidget.ItemView(
                        item = item,
                        isFocused = isFocused,
                        modifier = Modifier
                            .onFocusChanged {
                                isFocused = it.isFocused
                            }
                            .size(146.dp, 220.dp)
                    )
                }
                if (index == 0) {
                }
            }
        }
    }

}